/**
  ******************************************************************************
  * @file    usart.h
  * @brief   This file contains all the function prototypes for
  *          the usart.c file
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_H__
#define __USART_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;

/* USER CODE BEGIN Private defines */
#define USART_MAX_RECV_LEN		200					//�??大接收缓存数�??

//RS485 控制发�?��?�接�??
#define RS485_TX_EN()           HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,SET)
#define RS485_RX_EN()           HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,RESET)
//-----------测试、运行串口宏-------------------------------
//�????要换用串口的话，以下俩个宏需要修�????

//modbus的发送函数宏
//串口1 的宏：USART1_DataTX    串口2 的宏：USART2_DataTX
#define USARTx_DataTX         USART2_DataTX

//串口的数据存储结构体�????
//串口1 的宏：USART1_RX_BUF_MSG  串口2 的宏：USART2_RX_BUF_MSG
#define USARTx_RX_BUF_MSG     USART2_RX_BUF_MSG

//---------------------------------------------------------

//串口接收缓存结构�????
typedef struct _USART_RX_BUF_MSG
{
    uint8_t Buf[USART_MAX_RECV_LEN];  // 接收缓冲区间
    uint16_t RXIndex  ;                // 接收指针
    uint8_t  NewFrmFlag;               // 新的数据帧的标志�????
    uint8_t  RXTimeoutFlag;            // 超时判定
    uint16_t  RXTmrOutValSet;           // 超时设置时间
    uint16_t  RXTmrCntVal;              // 已用时计�?????

}USART_RX_BUF_MSG;

/* USER CODE END Private defines */

void MX_USART1_UART_Init(void);
void MX_USART2_UART_Init(void);

/* USER CODE BEGIN Prototypes */


void USART1_DataTX(uint8_t * pBuf, uint16_t len);
void USART2_DataTX(uint8_t * pBuf, uint16_t len);
void USART_RX_Ack_TimeOutCheck(USART_RX_BUF_MSG* ptrUS_RX);
void USART_ALL_TimeOutCheck(void);

extern USART_RX_BUF_MSG  USART1_RX_BUF_MSG;
extern USART_RX_BUF_MSG  USART2_RX_BUF_MSG;
/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __USART_H__ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
